﻿<UserControl x:Class="ModernUILogViewer.Content.ContentFileWatcherOptions"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:helpers="clr-namespace:ModernUILogViewer.Elements.Helpers"
             xmlns:settings="clr-namespace:ModernUILogViewer.Settings"
             xmlns:view="clr-namespace:ModernUILogViewer.View"
             xmlns:elem="clr-namespace:ModernUILogViewer.Elements"             
             xmlns:validation="clr-namespace:ModernUILogViewer.Validation"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"                
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"                
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             d:DesignHeight="430" d:DesignWidth="300"
             DataContext="{Binding Source={StaticResource mainVM}, Path=FileWatcherOptionsVM}"
             >
    
    <DockPanel>                
        <Grid DockPanel.Dock="Bottom">
            <ScrollViewer>
                <StackPanel HorizontalAlignment="Left" helpers:NotifierPanelHelper.EnableNotifier="True">
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}">INITIAL LIMIT DOWNLOAD (KB)</TextBlock>
                    <TextBlock Margin="{StaticResource DefaultTopLeftMargin}" Text="0 = no limit"></TextBlock>
                    <TextBox Margin="{StaticResource DefaultTopLeftMargin}" Width="80" TextAlignment="Right" HorizontalAlignment="Left">
                        <TextBox.Text>
                            <Binding Path="InitialLimit" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
                                <Binding.ValidationRules>
                                    <validation:NumberValidation />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>
                    </TextBox>
                    <CheckBox IsChecked="{Binding Path=EnableProxy, Mode=TwoWay}" HorizontalAlignment="Center" Margin="6">Enable Proxy</CheckBox>                    
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}" HorizontalAlignment="Center">PROXY</TextBlock>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}">HOST</TextBlock>
                    <TextBox Text="{Binding Path=Host, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}" Width="{StaticResource DefaultTextBoxWidth}"></TextBox>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopLeftMargin}">PORT</TextBlock>
                    <TextBox Margin="{StaticResource DefaultTopLeftMargin}" Width="80" HorizontalAlignment="Left">
                        <TextBox.Text>
                            <Binding Path="Port" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
                                <Binding.ValidationRules>
                                    <validation:NumberValidation />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>                        
                    </TextBox>
                    <CheckBox IsChecked="{Binding Path=EnableCredentials, Mode=TwoWay}" HorizontalAlignment="Center" Margin="6">Enable Credentials</CheckBox>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}" HorizontalAlignment="Center">CREDENTIALS</TextBlock>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}">USER</TextBlock>
                    <TextBox Text="{Binding Path=User, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}" Width="{StaticResource DefaultTextBoxWidth}"></TextBox>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}">PASSWORD</TextBlock>
                    <PasswordBox 
                    Margin="{StaticResource DefaultLeftMargin}"
                    helpers:PasswordHelper.Attach="True" 
                    helpers:PasswordHelper.Password="{Binding Path=Password, Mode=TwoWay}" Width="{StaticResource DefaultTextBoxWidth}" />
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}" Width="300">DOMAIN</TextBlock>
                    <TextBox Text="{Binding Path=Domain, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}" Width="{StaticResource DefaultTextBoxWidth}"></TextBox>
                    <StackPanel Orientation="Horizontal" Margin="0, 12, 0, 0">
                        <Button x:Name="savebtn" IsEnabled="False" Content="Save" Command="{Binding Source={StaticResource settingsmanager}, Path=SaveFileWatcherSettings}" CommandParameter="{Binding}" />
                        <Button x:Name="reloadbtn"  IsEnabled="False" Content="Reload" Command="{Binding Source={StaticResource settingsmanager}, Path=ReloadFileWatcherSettings}" CommandParameter="{Binding}" Margin="{StaticResource DefaultLeftMargin}" />
                    </StackPanel>                    
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </DockPanel>

    <i:Interaction.Triggers>   
        <helpers:RoutedEventTrigger RoutedEvent="{x:Static helpers:NotifierPanelHelper.ChildrenChangedEvent}">
            <ei:ChangePropertyAction TargetName="savebtn" PropertyName="IsEnabled" Value="True" />
            <ei:ChangePropertyAction TargetName="reloadbtn" PropertyName="IsEnabled" Value="True" />
        </helpers:RoutedEventTrigger>
        <i:EventTrigger EventName="SettingsSaved" SourceObject="{StaticResource settingsmanager}">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=savebtn}" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=reloadbtn}" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>
        <i:EventTrigger EventName="SettingsReloaded" SourceObject="{StaticResource settingsmanager}">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=reloadbtn}" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=savebtn}" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>             
    </i:Interaction.Triggers>

</UserControl>
